package com.cyt.web.controller.work.antiepidemic;

import com.cyt.base.enums.BusinessType;
import com.cyt.base.enums.OperatorType;
import com.cyt.base.model.dto.ReturnResult;
import com.cyt.base.util.StringUtils;
import com.cyt.sys.aspect.BaseLog;
import com.cyt.web.controller.base.BaseController;
import com.cyt.work.antiepidemic.model.po.AntiepidemicBuilding;
import com.cyt.work.antiepidemic.model.po.AntiepidemicCommunity;
import com.cyt.work.antiepidemic.model.vo.AntiepidemicBuildingVo;
import com.cyt.work.antiepidemic.service.AntiepidemicBuildingService;
import com.cyt.work.antiepidemic.service.AntiepidemicCommunityService;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * e门通-社区建筑信息控制层
 *
 * @author rong yuan
 * @date 2020-2-12 1:38:46
 */
@RestController
public class AntiepidemicBuildingController extends BaseController {

    @Resource
    private AntiepidemicBuildingService antiepidemicBuildingService;
    @Resource
    private AntiepidemicCommunityService antiepidemicCommunityService;

    /**
     * 统一跳转
     *
     * @param model 数据模型
     * @return Model
     * @author rong yuan
     * @date 2020-2-12 1:38:46
     */
    @RequestMapping("/work/antiepidemic/antiepidemicbuilding/*")
    public Model goPage(Model model) {
        return model;
    }

    @RequestMapping(value = "/work/antiepidemic/antiepidemicbuilding/getAntiepidemicBuildingList", method = RequestMethod.GET)
    public ModelAndView getDictContent(String communityId) {
        ModelAndView view = new ModelAndView("/work/antiepidemic/antiepidemicbuilding/antiepidemicBuildingList");
        view.addObject("communityId", communityId);
        AntiepidemicCommunity antiepidemicCommunity = antiepidemicCommunityService.selectByPrimaryKey(communityId);
        view.addObject("antiepidemicCommunity", antiepidemicCommunity);
        return view;
    }

    /**
     * 分页查询
     *
     * @param antiepidemicBuildingVo 接受参数对象
     * @param page                   当前页面
     * @param limit                  页面数量
     * @return ReturnResult
     * @author rong yuan
     * @date 2020-2-12 1:38:46
     */
    @BaseLog(module = "e门通", classz = "社区建筑信息", methods = "分页查询对象", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/work/antiepidemic/antiepidemicbuilding/page", method = RequestMethod.POST)
    public ReturnResult page(AntiepidemicBuildingVo antiepidemicBuildingVo, int page, int limit) {
        return antiepidemicBuildingService.page(antiepidemicBuildingVo, page, limit);
    }

    /**
     * 跳转添加或编辑界面
     *
     * @param id 主键
     * @return ReturnResult
     * @author rong yuan
     * @date 2020-2-12 1:38:46
     */
    @BaseLog(module = "e门通", classz = "社区建筑信息", methods = "跳转添加或编辑界面", businessType = BusinessType.GET, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/work/antiepidemic/antiepidemicbuilding/getEdit", method = RequestMethod.GET)
    public ModelAndView getEdit(String id, String applyId, String communityId) {
        ModelAndView view = new ModelAndView("/work/antiepidemic/antiepidemicbuilding/antiepidemicBuildingEdit");
        if (StringUtils.isNotBlank(id)) {
            AntiepidemicBuilding antiepidemicBuilding = antiepidemicBuildingService.selectByPrimaryKey(id);
            AntiepidemicCommunity antiepidemicCommunity = antiepidemicCommunityService.selectByPrimaryKey(antiepidemicBuilding.getCommunityId());
            antiepidemicBuilding.setCommunityName(antiepidemicCommunity.getBuildingName());
            view.addObject(antiepidemicBuilding);
        }
        view.addObject("applyId", applyId);
        AntiepidemicCommunity antiepidemicCommunity = antiepidemicCommunityService.selectByPrimaryKey(communityId);
        view.addObject("antiepidemicCommunity", antiepidemicCommunity);
        return view;
    }

    /**
     * 保存或更新
     *
     * @param request                请求对象
     * @param antiepidemicBuildingVo 接受参数对象
     * @return ReturnResult
     * @author rong yuan
     * @date 2020-2-12 1:38:46
     */
    @BaseLog(module = "e门通", classz = "社区建筑信息", methods = "保存或更新对象", businessType = BusinessType.INSERT, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/work/antiepidemic/antiepidemicbuilding/addOrUpdate", method = RequestMethod.POST)
    public ReturnResult addOrUpdate(HttpServletRequest request, AntiepidemicBuildingVo antiepidemicBuildingVo) {
        return antiepidemicBuildingService.addOrUpdate(antiepidemicBuildingVo, acceptCurrentUser(request));
    }

    /**
     * 根据条件逻辑删除
     *
     * @param request                请求对象
     * @param antiepidemicBuildingVo 接受参数对象
     * @return ReturnResult
     * @author rong yuan
     * @date 2020-2-12 1:38:46
     */
    @BaseLog(module = "e门通", classz = "社区建筑信息", methods = "逻辑删除对象", businessType = BusinessType.DELETE, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/work/antiepidemic/antiepidemicbuilding/remove", method = RequestMethod.GET)
    public ReturnResult remove(HttpServletRequest request, AntiepidemicBuildingVo antiepidemicBuildingVo) {
        return antiepidemicBuildingService.remove(antiepidemicBuildingVo, acceptCurrentUser(request));
    }

    /**
     * 根据条件物理删除
     *
     * @param request                请求对象
     * @param antiepidemicBuildingVo 接受参数对象
     * @return ReturnResult
     * @author rong yuan
     * @date 2020-2-12 1:38:46
     */
    @BaseLog(module = "e门通", classz = "社区建筑信息", methods = "物理对象对象", businessType = BusinessType.DELETE, operatorType = OperatorType.MANAGE)
    @RequestMapping(value = "/work/antiepidemic/antiepidemicbuilding/delete", method = RequestMethod.GET)
    public ReturnResult delete(HttpServletRequest request, AntiepidemicBuildingVo antiepidemicBuildingVo) {
        return antiepidemicBuildingService.delete(antiepidemicBuildingVo, acceptCurrentUser(request));
    }

    @RequestMapping(value = "/work/antiepidemic/antiepidemicbuilding/acceptSelect", method = RequestMethod.POST)
    public ReturnResult acceptSelect(String dictType, String communityId) {
        return antiepidemicBuildingService.acceptSelect(dictType, communityId);
    }

    @RequestMapping(value = "/work/antiepidemic/antiepidemicbuilding/importExcel", method = RequestMethod.POST)
    public ReturnResult importExcel(MultipartFile file, HttpServletRequest request, String applyId, String communityId) {
        return antiepidemicBuildingService.importExcel(file, applyId, communityId, acceptCurrentUser(request));
    }
}